import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
const isAdmin=(localStorage.getItem('role')=='admin')
/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */


export const constantRoutes1 = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
]


const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
// 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true },
  {
    path: '/',
    component: Layout,
    redirect: '/homePage',
    children: [{
      path: 'homePage',
      name: 'homePage',
      component: () => import('@/views/homePage/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/developers',
    component: Layout,
    redirect: '/developers/tableDev',
    name: '开发商',
    meta: { title: '开发商', icon: 'table' },
    children: [
      {
        path: 'tableDev',
        name: 'TableDev',
        component: () => import('@/views/developers/table'),
        meta: { title: '开发商列表', icon: 'table',admin:true }
      },
      {
        path: 'addDev',
        name: 'addDev',
        component: () => import('@/views/developers/add'),
        hidden:true,
        meta: { title: '添加(编辑)开发商', icon: 'table',admin:true }
      }
    ]
  },
  {
    path: '/building',
    component: Layout,
    redirect: '/building/tableBui',
    name: '楼盘',
    meta: { title: '楼盘', icon: 'tree' },
    children: [
      {
        path: 'tableBui',
        name: 'tableBui',
        component: () => import('@/views/building/table'),
        meta: { title: '楼盘列表', icon: 'tree',admin:true }
      },
      {
        path: 'msgBui',
        name: 'msgBui',
        component: () => import('@/views/building/index'),
        meta: { title: '楼盘信息', icon: 'tree',all:true }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/tableUser',
    name: '用户',
    meta: { title: '用户', icon: 'user' },
    children: [
      {
        path: 'tableUser',
        name: 'tableUser',
        component: () => import('@/views/user/tableUser'),
        meta: { title: '用户列表', icon: 'user',admin:true }
      },
      {
        path: 'tableUsb',
        name: 'tableUsb',
        hidden:true,
        component: () => import('@/views/user/tableUsb'),
        meta: { title: '用户缴纳诚意金楼盘列表', icon: 'user' }
      },
    ]
  },
  {
    path: '/auditBuiActivity',
    component: Layout,
    redirect: '/auditBuiActivity/tableBuiAct',
    name: '银行活动',
    meta: { title: '银行活动', icon: 'nested' },
    children: [
      {
        path: 'tableBuiAct',
        name: 'tableBuiAct',
        component: () => import('@/views/auditBuiActivity/table'),
        meta: { title: '楼盘活动列表', icon: 'nested',admin:true }
      },
      {
        path: 'auditAct',
        name: 'auditAct',
        hidden:true,
        component: () => import('@/views/auditBuiActivity/audit'),
        meta: { title: '审核楼盘活动', icon: 'nested',admin:true }
      }
    ]
  },
  {
    path: '/activity',
    component: Layout,
    redirect: '/activity/tableAct',
    name: '银行活动',
    meta: { title: '银行活动', icon: 'link' },
    children: [
      {
        path: 'tableAct',
        name: 'tableAct',
        component: () => import('@/views/activity/table'),
        meta: { title: '银行活动列表', icon: 'link',admin:true }
      },
      {
        path: 'addAct',
        name: 'addAct',
        hidden:true,
        component: () => import('@/views/activity/add'),
        meta: { title: '添加(编辑)银行活动', icon: 'link',admin:true }
      }
    ]
  },
  {
    path: '/activityBui',
    component: Layout,
    redirect: '/activityBui/tableBui',
    name: '楼盘活动',
    meta: { title: '楼盘活动', icon: 'nested' },
    children: [
      {
        path: 'tableBui',
        name: 'tableBui',
        component: () => import('@/views/buiActivity/table'),
        meta: { title: '楼盘活动列表', icon: 'nested' }
      },
      {
        path: 'addBui',
        name: 'addBui',
        hidden:true,
        component: () => import('@/views/buiActivity/add'),
        meta: { title: '添加(编辑)楼盘活动', icon: 'nested' }
      }
    ]
  },
  {
    path: '/sincerity',
    component: Layout,
    redirect: '/sincerity/tableUser',
    name: '诚意金',
    meta: { title: '诚意金', icon: 'user' },
    children: [
      {
        path: 'tableUser',
        name: 'tableUser',
        component: () => import('@/views/sincerity/tableUser'),
        meta: { title: '诚意金缴纳列表', icon: 'user' }
      },
      {
        path: 'tableUnfreeze',
        name: 'tableUnfreeze',
        hidden:true,
        component: () => import('@/views/sincerity/tableUnfreeze'),
        meta: { title: '申请解冻列表', icon: 'user' }
      },
    ]
  },
  {
    path: '/appoint',
    component: Layout,
    redirect: '/appoint/tableApp',
    name: '预约看房列表',
    meta: { title: '预约看房列表', icon: 'table', },
    children: [
      {
        path: 'tableApp',
        name: 'tableApp',
        component: () => import('@/views/appoint/table'),
        meta: { title: '预约看房列表', icon: 'table' }
      },
    ]
  },
]
// export default new Router({
//   // mode: 'history', // require service support
//   scrollBehavior: () => ({
//     y: 0
//   }),
//   routes: constantRoutes
// })
function createRouter(){
  return new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({
      y: 0
    }),
    routes: constantRoutes,
    routesTemp: constantRoutes,
  })
}
const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
